<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS的数据类型</title>
</head>
<body>
    <script>
        //数据类型=原始类型+引用类型
        var a = 1;
        var b=3.14;
        console.log(a,b);
        console.log(typeof a,typeof b);//number number
        var c="hello";
        var d="world";
        console.log(c,d);
        console.log(typeof c,typeof d);//string string
        var e=true;
        var f=false;
        console.log(e,f);
        console.log(typeof e,typeof f);//boolean boolean
        var g;//声明了变量但未赋值，推断不出来类型，就是未定义型
        console.log(g,typeof g);//undefined 'undefined'

        /*引用类型:Object Array Function Date ...*/
        let obj={};
        console.log(obj,typeof obj);//{} 'object'
        obj.name="张三";
        obj.age=18;
        console.log(obj);//{name: '张三', age: 18}
        console.log(obj.name,obj.age);//张三 18
        let obj2={
            name:"张三",
            age:18
        };
        console.log(obj2);
        console.log(obj2.name,obj2.age);
        obj2.like="play";
        console.log(obj2);//{name: '张三', age: 18, like: 'play'}
        console.log(obj2.eat);//访问对象不存在的属性，也会得到undefined

        //数组
        let arr=[1,2.33,'3',true];
        console.log(arr);
        console.log(arr[0],arr[1],arr[2],arr[3]);
        console.log(arr[100]);//访问数组不存在的下标，也会得到undefined
        let s1={
            name:"张三",
            age:18,
            score:[100,90,80]
        };
        let s2={
            name:"李四",
            age:19,
            score:[93,92,79]
        };
        let s3={
            name:"王五",
            age:20,
            score:[93,82,75]
        };
        let students=[s1,s2,s3];
        console.log(students);

        //数据类型转换
        //Number() 将参数转为数值类型，如果得不到数字类型的结果会得到NaN(Not a Number)
        console.log(Number(true));//1
        console.log(Number(false));//0
        console.log(Number("123"));//123
        console.log(Number(23.45));//23.45
        console.log(Number(23));//23
        console.log(Number("哈哈哈"));//NaN

        //Boolean() 将参数转为布尔类型的结果
        //0 null undefined NaN '' 空字符串 都会得到false
        console.log(Boolean(0));// false
        console.log(Boolean(null));// false
        console.log(Boolean(undefined));// false
        console.log(Boolean(NaN));// false
        console.log(Boolean(''));// false
        console.log(Boolean(' '));// true
        console.log(Boolean('hhh'));// true
        console.log(Boolean(1));// true
    </script>
</body>
</html>